package com.zhike.b2b.stock.impl;

import com.saas.biz.commen.CommGetId;
import com.saas.biz.companylevelMgr.CompanyLevelInfo;
import com.saas.biz.dao.stockorderDAO.RegbuyExt;
import com.saas.biz.scoreListMgr.ScoreListInfo;
import com.saas.sys.buffer.Buffers;
import com.saas.sys.exp.SaasApplicationException;
import com.saas.sys.log.Logger;
import com.zhike.b2b.dao.Dbtable;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;

public class RegbuyInfo
{
  Dbtable tradeQuery = new Dbtable();
  Logger log = new Logger(this);
  Buffers inBuffer;
  Buffers outBuffer;
  ArrayList queryResult = new ArrayList();

  public Buffers getInBuffer()
  {
    return this.inBuffer;
  }

  public void setInBuffer(Buffers paramBuffers)
  {
    this.inBuffer = paramBuffers;
  }

  public Logger getLog()
  {
    return this.log;
  }

  public void setLog(Logger paramLogger)
  {
    this.log = paramLogger;
  }

  public Buffers getOutBuffer()
  {
    return this.outBuffer;
  }

  public void setOutBuffer(Buffers paramBuffers)
  {
    this.outBuffer = paramBuffers;
  }

  public ArrayList getQueryResult()
  {
    return this.queryResult;
  }

  public void setQueryResult(ArrayList paramArrayList)
  {
    this.queryResult = paramArrayList;
  }

  public Dbtable getTradeQuery()
  {
    return this.tradeQuery;
  }

  public void setTradeQuery(Dbtable paramDbtable)
  {
    this.tradeQuery = paramDbtable;
  }

  public void addReg(Buffers paramBuffers)
    throws SaasApplicationException
  {
    this.log.LOG_INFO("进入addReg方法...");
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    CommGetId localcommGetId = new CommGetId();
    String str1 = "";
    str1 = localcommGetId.getAutoTradeID(paramBuffers.getString("CUST_ID"), "out_of_stock", "trade_id");
    int i = -1;
    try
    {
      i = addReg(paramBuffers, str1);
    }
    catch (SaasApplicationException localSaasApplicationException)
    {
      this.log.LOG_INFO(localSaasApplicationException.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
    String str2 = paramBuffers.getString("TRADE_TYPE_CODE");
    String str3 = new ScoreListInfo().getOperName(str2);
    String str4 = new CompanyLevelInfo().getLevelId(paramBuffers.getString("CUST_ID"));
    log.LOG_DEBUG("执行积分操作---------------------------------------------------------------");
    log.LOG_DEBUG("level_id-----------------------------------------------------------------" + str4);
    this.outBuffer.setString("BUILD", "1");
    this.outBuffer.setString("TABLENAME", "out_of_stock");
    this.outBuffer.setString("ID", str1);
    this.outBuffer.setString("OPER_NAME", str3);
    this.log.LOG_INFO("退出addReg方法...");
  }

  public int addReg(Buffers paramBuffers, String paramString)
    throws SaasApplicationException
  {
    RegbuyExt localRegbuyExt = new RegbuyExt();
    localRegbuyExt.setParam(":VTRADE_ID", paramString);
    localRegbuyExt.setParam(":VCLASS_ID", paramBuffers.getString("CLASS_ID"));
    localRegbuyExt.setParam(":VCLASS_NAME", paramBuffers.getString("CLASS_NAME"));
    localRegbuyExt.setParam(":VTITLE", paramBuffers.getString("TITLE"));
    localRegbuyExt.setParam(":VIN_DATE", paramBuffers.getString("IN_DATE"));
    localRegbuyExt.setParam(":VDESCRIPTION", paramBuffers.getString("DESCRIPTION"));
    localRegbuyExt.setParam(":VCUST_ID", paramBuffers.getString("CUST_ID"));
    localRegbuyExt.setParam(":VUSER_ID", paramBuffers.getString("USER_ID"));
    this.tradeQuery.executeBy(localRegbuyExt.insBy("INS_REGBUY"));
    this.outBuffer.setString("ROOT_ID", paramString);
    return 0;
  }

  public ArrayList selectReg(String paramString)
    throws SaasApplicationException
  {
    ArrayList localArrayList = new ArrayList();
    RegbuyExt localRegbuyExt = new RegbuyExt();
    localRegbuyExt.setParam(":VTRADE_ID", paramString);
    localArrayList = localRegbuyExt.selByList("SELECT_BY_TRADE_ID");
    return localArrayList;
  }

  public void delReg(Buffers paramBuffers)
  {
    this.log.LOG_INFO("进入delReg方法...");
    this.outBuffer = paramBuffers;
    String str = paramBuffers.getString("trade_id");
    int i = -1;
    try
    {
      i = delReg(str);
    }
    catch (SaasApplicationException localSaasApplicationException)
    {
      this.log.LOG_INFO(localSaasApplicationException.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
    this.log.LOG_INFO("退出delReg方法...");
  }

  public int delReg(String paramString)
    throws SaasApplicationException
  {
    RegbuyExt localRegbuyExt = new RegbuyExt();
    localRegbuyExt.setParam(":VTRADE_ID", paramString);
    this.tradeQuery.executeBy(localRegbuyExt.insBy("DEL_REG"));
    return 0;
  }

  public ArrayList selectRegsbm(int paramInt1, int paramInt2, String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    if (paramInt1 > 1)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    else
      paramInt1 = 0;
    ArrayList localArrayList = new ArrayList();
    RegbuyExt localRegbuyExt = new RegbuyExt();
    if (paramString1.equals("all"))
      localRegbuyExt.setParam(":VREAD_STATE", "%");
    else
      localRegbuyExt.setParam(":VREAD_STATE", "%" + paramString1 + "%");
    if (paramString2.equals(""))
      localRegbuyExt.setParam(":VTITLE", "%");
    else
      localRegbuyExt.setParam(":VTITLE", "%" + paramString2 + "%");
    localRegbuyExt.setParam(":VCUST_ID", paramString3);
    localArrayList = localRegbuyExt.selByList("SELECT_REGS_BY_MEMBER", paramInt1, paramInt2);
    return localArrayList;
  }

  public int selectRegsbm(String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    ArrayList localArrayList = new ArrayList();
    RegbuyExt localRegbuyExt = new RegbuyExt();
    if (paramString1.equals("all"))
      localRegbuyExt.setParam(":VREAD_STATE", "%");
    else
      localRegbuyExt.setParam(":VREAD_STATE", "%" + paramString1 + "%");
    if (paramString2.equals(""))
      localRegbuyExt.setParam(":VTITLE", "%");
    else
      localRegbuyExt.setParam(":VTITLE", "%" + paramString2 + "%");
    localRegbuyExt.setParam(":VCUST_ID", paramString3);
    localArrayList = localRegbuyExt.selByList("SELECT_REGS_BY_MEMBER");
    if (localArrayList != null)
      return localArrayList.size();
    return 0;
  }

  public ArrayList selectRegsba(int paramInt1, int paramInt2, String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    if (paramInt1 > 1)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    else
      paramInt1 = 0;
    ArrayList localArrayList = new ArrayList();
    RegbuyExt localRegbuyExt = new RegbuyExt();
    if (paramString1.equals("all"))
      localRegbuyExt.setParam(":VREAD_STATE", "%");
    else
      localRegbuyExt.setParam(":VREAD_STATE", "%" + paramString1 + "%");
    if (paramString2.equals(""))
      localRegbuyExt.setParam(":VTITLE", "%");
    else
      localRegbuyExt.setParam(":VTITLE", "%" + paramString2 + "%");
    if (paramString3.equals("0all"))
    {
      localArrayList = localRegbuyExt.selByList("SELECT_REGS_BY_ALL_ADMIN", paramInt1, paramInt2);
    }
    else
    {
      localRegbuyExt.setParam(":VRE_USER", paramString3);
      localArrayList = localRegbuyExt.selByList("SELECT_REGS_BY_ADMIN", paramInt1, paramInt2);
    }
    return localArrayList;
  }

  public int selectRegsba(String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    ArrayList localArrayList = new ArrayList();
    RegbuyExt localRegbuyExt = new RegbuyExt();
    if (paramString1.equals("all"))
      localRegbuyExt.setParam(":VREAD_STATE", "%");
    else
      localRegbuyExt.setParam(":VREAD_STATE", "%" + paramString1 + "%");
    if (paramString2.equals(""))
      localRegbuyExt.setParam(":VTITLE", "%");
    else
      localRegbuyExt.setParam(":VTITLE", "%" + paramString2 + "%");
    if (paramString3.equals("0all"))
    {
      localArrayList = localRegbuyExt.selByList("SELECT_REGS_BY_ALL_ADMIN");
    }
    else
    {
      localRegbuyExt.setParam(":VRE_USER", paramString3);
      localArrayList = localRegbuyExt.selByList("SELECT_REGS_BY_ADMIN");
    }
    if (localArrayList != null)
      return localArrayList.size();
    return 0;
  }

  public void replyBa(Buffers paramBuffers)
    throws SaasApplicationException
  {
    this.log.LOG_INFO("进入replyBa方法...");
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    String str = paramBuffers.getString("trade_id");
    int i = -1;
    try
    {
      i = replyBa(paramBuffers, str);
    }
    catch (SaasApplicationException localSaasApplicationException)
    {
      this.log.LOG_INFO(localSaasApplicationException.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
    this.log.LOG_INFO("退出replyBa方法...");
  }

  public int replyBa(Buffers paramBuffers, String paramString)
    throws SaasApplicationException
  {
    RegbuyExt localRegbuyExt = new RegbuyExt();
    localRegbuyExt.setParam(":VTRADE_ID", paramString);
    localRegbuyExt.setParam(":VRE_CONTENT", paramBuffers.getString("RE_CONTENT"));
    localRegbuyExt.setParam(":VRE_USER_ID", paramBuffers.getString("RE_USER_ID"));
    this.tradeQuery.executeBy(localRegbuyExt.insBy("INS_REPLY"));
    this.outBuffer.setString("ROOT_ID", paramString);
    return 0;
  }

  public String getRe_users()
  {
    String str1 = "select u.user_id,u.contact_name,c.cust_type from user_info u,company c where u.cust_id=c.cust_id and c.cust_type=0";
    ArrayList localArrayList = new ArrayList();
    localArrayList =  null;//todo 在此执行SQL localJDBCExceute.excute(str1);
    String str2 = "";
    String str3 = "";
    String str4 = "";
    if ((localArrayList != null) && (localArrayList.size() > 0))
      for (int i = 0; i < localArrayList.size(); i++)
      {
        HashMap localHashMap = (HashMap)localArrayList.get(i);
        if (localHashMap.get("user_id") != null)
          str2 = localHashMap.get("user_id").toString();
        if (localHashMap.get("contact_name") != null)
          str3 = localHashMap.get("contact_name").toString();
        str4 = str4 + "<option value=" + str2 + "   id=" + str2 + ">" + str3 + "</option>";
      }
    return str4;
  }

  public int getBuyingNum()
    throws SaasApplicationException
  {
    RegbuyExt localRegbuyExt = new RegbuyExt();
    ArrayList localArrayList = new ArrayList();
    localArrayList = localRegbuyExt.selByList("SEL_BUYING_STATE_BY_CHECKTWO");
    if ((localArrayList != null) && (localArrayList.size() > 0))
      return localArrayList.size();
    return 0;
  }
}

